package router

import (
	"3-19yk/client/client"
	"3-19yk/client/enit"
	"3-19yk/client/response"
	"3-19yk/common/proto/user"
	"fmt"
	"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {
	var data enit.Login
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	login, err := client.Login(c, &user.LoginReq{
		Phone:    data.Phone,
		Password: data.Password,
	})
	if err != nil {
		response.ResPonseError(c, fmt.Errorf("注册失败"))
		return
	}
	response.ResPonseSuccess(c, login)
}

func RealName(c *gin.Context) {
	ui := c.GetUint("userId")
	var data enit.RealName
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	name, err := client.RealName(c, &user.RealNameReq{
		UserId:    int64(ui),
		RealNames: data.RealNames,
		IdCard:    data.IdCard,
	})
	if err != nil {
		response.ResPonseError(c, err.Error())
		return
	}
	response.ResPonseSuccess(c, name)
}
